#ifndef LIT__EDITOR__DIALOG__HH__
#define LIT__EDITOR__DIALOG__HH__

#include "LitEditorPrerequisites.h"
#include "LitEditorDialogReturn.hpp"
#include <QtGui>
#include <QtWidgets>

namespace Lit
{
	namespace Editor
	{
		class StringMapConnecter : public QObject
		{
			Q_OBJECT

		protected:
			StringMapReturn::MapType						mSettings;
			StringMapReturn::MapType						mInitialSettings;
			QTableWidget *									mTable;
			std::unordered_map<QWidget*, QTableWidgetItem*> mMapping;

		public:
			StringMapConnecter( const StringMapReturn::MapType & settings, QTableWidget * table );
			~StringMapConnecter();

			void map( QTableWidgetItem * item, QWidget* w , const char * widget_emitter, const char * this_receiver );

			QTableWidgetItem * findItem( QWidget * from );
				
			std::unordered_map<QWidget*, QTableWidgetItem*>::iterator findMapping( size_t row );
			std::unordered_map<QWidget*, QTableWidgetItem*>::const_iterator findMapping( size_t row ) const;
			const std::unordered_map<QWidget*, QTableWidgetItem*>& getMapping() const;
			std::unordered_map<QWidget*, QTableWidgetItem*>& getMapping();

			const StringMapReturn::MapType& getSettings() const;
			StringMapReturn::MapType& getSettings();

			const StringMapReturn::MapType& getInitialSettings() const;
			StringMapReturn::MapType& getInitialSettings();

		protected slots:
			void itemChanged( QTableWidgetItem * item );
			void on_restoreDefault_triggered( );
		};
		class LIT_API Dialog : public QDialog
		{
			QFormLayout *		mLayout;
			QHBoxLayout *		mBottomLayout;
			QDialogButtonBox *	mButtons;
		public:
			enum IconType
			{
				DI_NO_ICON=0,
				DI_WARNING,
				DI_QUESTION,
				DI_EXCLAMATION,
				DI_CRITICAL,
				DI_INFORMATION,
				DI_SETTINGS
			};

			Dialog( const std::string &title="Dialog", const QIcon &icon = QIcon(), QWidget * parent = 0 );
			virtual ~Dialog( );
			
			QWidget* addRow( QWidget * widget ) ;
			QWidget* addRow( const std::string &name, QWidget * widget );
			QLayout* addRow( QLayout * lay ) ;
			QLayout* addRow( const std::string &name, QLayout * lay ) ;
			void clear();

			int exec()
			{
				return QDialog::exec();
			}
			QFormLayout * getLayout();
			const QFormLayout * getLayout() const;
			QDialogButtonBox* getButtons();
			const QDialogButtonBox* getButtons() const;
			static QIcon grabIcon( IconType ico );
			static StringReturn ask( QWidget * parent, const std::string &title, const std::string &question, const std::string &default_val = "", IconType type = DI_QUESTION );
			static void warn( QWidget * parent, const std::string &title, const std::string &description );
			QStyle* changeStyle( QWidget* parent, const std::string &title = "Change the current style", bool apply_to_qapp=true );
			static void inform( QWidget * parent, const std::string &title, const std::string &description );
			static StringMapReturn configure( QWidget * parent, const std::string &title, const StringMapReturn::MapType &settings, IconType type = DI_SETTINGS );
		};
	};
};
#endif